VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Proper case function hi iT is CoOl> Hi It is cool

by Vitaly (7 Submissions)
Category: Coding Standards
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (5 Votes)

To fix the input of the user. For example if the user inputs a bad case sentance it will make it normal:
what do yOu think? -> What do you think?
It checks for ./?/!. Have fun.

Inputs
Bad case string
Code Returns
Proper case string

Rate Proper case function hi iT is CoOl> Hi It is cool

Function Proper(Text As String)
Dim FirstLetter%, I%, BadFormat%, J%, Loc%, Sta%
Dim BreakL$, BreakR$
'------------------------
Text = LCase(Text)
FirstLetter = Asc(Mid(Text, 1, 1))
If FirstLetter >= 97 And FirstLetter <= 122 Then
  Text = Right(Text, Len(Text) - 1)
  Text = Chr(FirstLetter - 32) & Text
End If
For I = 1 To Len(Text) - 2
  If Mid(Text, I, 1) = "." And Asc(Mid(Text, I + 2, 1)) >= 97 And Asc(Mid(Text, I + 2, 1)) <= 122 _
   Then BadFormat = BadFormat + 1
  If Mid(Text, I, 1) = "!" And Asc(Mid(Text, I + 2, 1)) >= 97 And Asc(Mid(Text, I + 2, 1)) <= 122 _
   Then BadFormat = BadFormat + 1
  If Mid(Text, I, 1) = "?" And Asc(Mid(Text, I + 2, 1)) >= 97 And Asc(Mid(Text, I + 2, 1)) <= 122 _
   Then BadFormat = BadFormat + 1
Next I
Loc = 1
For J = 1 To BadFormat
  Sta = 200
  If InStr(Loc, Text, ".") <> 0 Then Sta = InStr(Loc, Text, ".")
  If InStr(Loc, Text, "?") < Sta And InStr(Loc, Text, "?") <> 0 _
   Then Sta = InStr(Loc, Text, "?")
  If InStr(Loc, Text, "!") < Sta And InStr(Loc, Text, "!") <> 0 _
   Then Sta = InStr(Loc, Text, "!")
  For I = Sta To Len(Text)
    If Asc(Mid(Text, I, 1)) >= 97 And Asc(Mid(Text, I, 1)) <= 122 Then
      Loc = I + 1
      FirstLetter = Asc(Mid(Text, I, 1))
      BreakL = Left(Text, I - 1)
      BreakR = Right(Text, Len(Text) - I)
      Text = BreakL & Chr(FirstLetter - 32) & BreakR
      Exit For
    End If
  Next I
Next J
Proper = Text
End Function

Download this snippet    Add to My Saved Code

Proper case function hi iT is CoOl> Hi It is cool Comments

No comments have been posted about Proper case function hi iT is CoOl> Hi It is cool. Why not be the first to post a comment about Proper case function hi iT is CoOl> Hi It is cool.

Post your comment

Subject:
Message:
0/1000 characters